/*****************************************************************************
*    Ali Corp. All Rights Reserved. 2007 Copyright (C)
*
*    File:    scart.c
*    
*    Description:    This file contains all functions definition 
*		             of SCART SWITCH  modulator driver.
*    History: 
*           Date            Athor        Version          Reason
*	    ============	=============	=========	=================
*	1.	Aug.21.2007      Goliath Peng       Ver 0.1    Create file.
*****************************************************************************/

#include <types.h>
#include <retcode.h>
#include <api/libc/alloc.h>
#include <api/libc/printf.h>
#include <osal/osal_int.h>
#include <hld/hld_dev.h>
#include <hld/scart/scart.h>


INT32 scart_open(struct scart_device *dev)
{
	INT32 result = SUCCESS;
	
	/* If openned already, exit */
	if (dev->flags & HLD_DEV_STATS_UP)
	{
		PRINTF("scart_open: warning - device %s openned already!\n", dev->name);
		return SUCCESS;
	}
	
	/* Open this device */
	if (dev->open)
	{
		result = dev->open(dev);
	}
	
	/* Setup init work mode */
	if (result == SUCCESS)
	{
		dev->flags |= (HLD_DEV_STATS_UP | HLD_DEV_STATS_RUNNING);
		
	}
	
	return result;
}


INT32 scart_close(struct scart_device *dev)
{
	INT32 result = SUCCESS;

	if ((dev->flags & HLD_DEV_STATS_UP) == 0)
	{
		PRINTF("scart_close: warning - device %s closed already!\n", dev->name);
		return SUCCESS;
	}
	
	/* Stop device */
	if (dev->close)
	{
		result = dev->close(dev);
	}
	
	/* Update flags */
	dev->flags &= ~(HLD_DEV_STATS_UP | HLD_DEV_STATS_RUNNING);
	
	return result;
}


INT32 scart_io_control(struct scart_device *dev, INT32 cmd, UINT32 param)
{	
	if (dev->ioctl)
	{
		return dev->ioctl(dev, cmd, param);
	}
	
	return SUCCESS;
}

